package org.hzero.interfaces.common.concurrent;


import org.hzero.interfaces.common.entity.KnifeInterfaceLogRecord;
import org.hzero.interfaces.common.mapper.KnifeInterfaceLogRecordMapper;
import org.hzero.interfaces.common.utils.KnifeSpringUtil;

/**
 * 1 记录接口请求日志的线程
 *
 * @author: tianhao.luo@hand-china.com 2021/6/30  上午11:02
 */
public class KnifeInterfaceRecordThread implements Runnable {
    private final static KnifeInterfaceLogRecordMapper KNIFE_INTERFACE_LOG_RECORD_MAPPER;

    static {
        // 1.加载mapper
        KNIFE_INTERFACE_LOG_RECORD_MAPPER = KnifeSpringUtil.getBean(KnifeInterfaceLogRecordMapper.class);
    }

    private final KnifeInterfaceLogRecord knifeInterfaceLogRecord;

    public KnifeInterfaceRecordThread(KnifeInterfaceLogRecord knifeInterfaceLogRecord) {
        this.knifeInterfaceLogRecord = knifeInterfaceLogRecord;
    }

    @Override
    public void run() {
        // 保存数据,因为该日志表没有表主键,所以不需要害怕插入冲突的问题
        KNIFE_INTERFACE_LOG_RECORD_MAPPER.insertSelective(knifeInterfaceLogRecord);
    }
}
